numb=int(input())
if numb<1000 or numb>9999:
	print(0)
else:
	power=[0]
	def checker(num):
		if num <= 1:
			return False
		for i in range(2, int(num**0.5)+1):
			if num%i==0:
				return False
		return True
	s=str(numb)
	for i in range(1, 5):
		for q in range(i, 5):
			num=int(s[i-1:q])
			if checker(num):
				power.append(num)
	checker(num)
	print(max(power))